CREATE TABLE Author
(
	AuthorID  integer  IDENTITY (1,1) ,
	FirstMiddleName  nvarchar(40)  NULL ,
	LastName  nvarchar(20)  NULL ,
	FullName  varchar(20)  NULL ,
	BirthDay  smalldatetime  NULL ,
	Email  varchar(200)  NULL 
)
go


ALTER TABLE Author
	ADD CONSTRAINT  XPKAuthor PRIMARY KEY   NONCLUSTERED (AuthorID  ASC)
go


CREATE TABLE AuthorBook
(
	BookID  integer  NOT NULL ,
	AuthorID  integer  NOT NULL 
)
go


ALTER TABLE AuthorBook
	ADD CONSTRAINT  XPKAuthorBook PRIMARY KEY   NONCLUSTERED (BookID  ASC,AuthorID  ASC)
go


CREATE TABLE Book
(
	BookID  integer  IDENTITY (1,1) ,
	Title  nvarchar(200)  NULL ,
	CompanyID  integer  NULL ,
	UserID  integer  NULL ,
	UserName  nvarchar(80)  NULL ,
	CreateDate  datetime  NULL ,
	ModifiedDate  datetime  NULL ,
	CategoryID  integer  NULL 
)
go


ALTER TABLE Book
	ADD CONSTRAINT  XPKBook PRIMARY KEY   NONCLUSTERED (BookID  ASC)
go


CREATE TABLE Category
(
	CategoryID  integer  IDENTITY (1,1) ,
	Name  nvarchar(80)  NULL ,
	Description  nvarchar(200)  NULL 
)
go


ALTER TABLE Category
	ADD CONSTRAINT  XPKCategory PRIMARY KEY   NONCLUSTERED (CategoryID  ASC)
go


CREATE TABLE Person
(
	PersonID  uniqueidentifier  NOT NULL ,
	Name  nvarchar(100)  NULL 
)
go


ALTER TABLE Person
	ADD CONSTRAINT  XPKPerson PRIMARY KEY   NONCLUSTERED (PersonID  ASC)
go



ALTER TABLE AuthorBook
	ADD CONSTRAINT  R_6 FOREIGN KEY (BookID) REFERENCES Book(BookID)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go


ALTER TABLE AuthorBook
	ADD CONSTRAINT  R_7 FOREIGN KEY (AuthorID) REFERENCES Author(AuthorID)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go



ALTER TABLE Book
	ADD CONSTRAINT  R_5 FOREIGN KEY (CategoryID) REFERENCES Category(CategoryID)
		ON DELETE NO ACTION
		ON UPDATE NO ACTION
go


